package com.china08.yxyapi.api.manage.tec.teaching.homework.worklist.workinfo.report;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.model.YxyApiPageReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.homework.HomeworkTaskQuesRepository;

/**
 * 主观题试题数量
 */
@CrossOrigin
@RestController
public class HomeworkQuesType34TotalController extends YxyApiBaseController {

    @Autowired
    HomeworkTaskQuesRepository homeworkTaskQuesRepository;

    @ResponseBody
    @RequestMapping(value = "/api_yw/manage/tec/teaching/homework/worklist/workinfo/report/questype/total", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(//
            HttpServletRequest request, //
            HttpServletResponse response, //
            @RequestParam String taskId, //
            RespModel respModel) throws ParseException {
    		
        // 单选题、多选题数量
        List<String> quesTypes = new ArrayList<>();
        quesTypes.add("0");
        quesTypes.add("1"); 
        Integer total0_1 = homeworkTaskQuesRepository.countByTaskIdAndQuesTypeIn(taskId, quesTypes);
        total0_1 = total0_1 == null ? 0 : total0_1;
        
        // 批阅主观题数量
        List<String> quesTypes3_4 = new ArrayList<>();
        quesTypes3_4.add("3");
        quesTypes3_4.add("4");
        Integer total3_4 = homeworkTaskQuesRepository.countByTaskIdAndQuesTypeIn(taskId, quesTypes3_4);
        total3_4 = total3_4 == null ? 0 : total3_4;
        
        // 批阅通知类试题数量【忽略不要学生作答通知试题】
        Integer total2 = homeworkTaskQuesRepository.countByTaskIdAndQuesTypeAndIfNeedSumbit(taskId, "2", true);
        total2 = total2 == null ? 0 : total2;
        
        // 阅读类试题数量
        Integer total5 = homeworkTaskQuesRepository.countByTaskIdAndQuesType(taskId, "5");
        total5 = total5 == null ? 0 : total5;
    	
    	RespModel model = new RespModel();
    	model.total01 = total0_1;
    	model.total34 = total3_4;
    	model.total2 = total2;
    	model.total5 = total5;
    	model.total = total0_1 + total3_4 + total2 + total5;
        return model;
    }

    /** 响应 **/
    public static class RespModel extends YxyApiRespModel {
    	public Integer total = 0;
        public Integer total01 = 0;
        public Integer total34 = 0;
        public Integer total2 = 0;
        public Integer total5 = 0;
    }
}
